package io.renren.modules.alarm.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.alarm.entity.GuardEntity;
import io.renren.modules.alarm.service.GuardService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author zhourl
 * @email zhou11258@foxmail.com
 * @date 2022-03-06 20:24:38
 */

@RestController
@RequestMapping("alarm/guard")
@Api("用户接口")
public class GuardController {
    @Autowired
    private GuardService guardService;
    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("alarm:guard:list")
    public R list(@RequestParam(required = false) Map<String, Object> params) {
        PageUtils page = guardService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{userId}")
    @ApiOperation("个人信息")
    public R info(@PathVariable("userId") Long userId) {
        GuardEntity guard = guardService.getById(userId);
        return R.ok().put("guard", guard);
    }

    /**
     * 保存
     *
     */
    @PostMapping("/save")
    @RequiresPermissions("alarm:guard:save")
    public R save(@RequestBody GuardEntity guard) {
        guardService.save(guard);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("alarm:guard:update")
    @ApiOperation("修改信息")
    public R update(@RequestBody GuardEntity guard) {
        guardService.updateById(guard);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("alarm:guard:delete")
    public R delete(@RequestBody Long[] userIds) {
        guardService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
